﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using yichu_front;

namespace yichu_manager.BLL
{
    public static class NoticeService
    {
        /// <summary>
        /// 获取最新的通告
        /// </summary>
        /// <returns></returns>
        public static Notice getLastNotice()
        {
            return SqlSugarHelp.scope.Queryable<Notice>().OrderBy(it => it.通告时间, SqlSugar.OrderByType.Desc).First();
        }
        /// <summary>
        /// 发布新通告
        /// </summary>
        /// <param name="not"></param>
        /// <returns></returns>
        public static int addNotcie(string not)
        {
            Notice notice = new Notice();
            notice.通告内容 = not;
            notice.通告时间 = DateTime.Now;
            return SqlSugarHelp.scope.Insertable(notice).ExecuteCommand();
        }

        public static List<Notice> getAllNotice()
        {
            List<Notice> notices = null;
                SqlSugarHelp.scope.CurrentConnectionConfig.ConnectionString = "";
                SqlSugarHelp.scope.Queryable<Notice>().ToList();
            if (notices != null && notices.Count > 0)
            {
                for (int i = 0; i < notices.Count; i++)
                {
                    notices[i].序号 = i + 1;
                }
            }
            return notices;
        }
    }
}
